<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>位置上报</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4ecf5 100%);
            color: #333;
            line-height: 1.6;
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px 0;
        }

        .page-title {
            text-align: center;
            margin-bottom: 40px;
            color: #165DFF;
            font-weight: 700;
            font-size: 32px;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background: rgba(0, 0, 0, 0.6);
            backdrop-filter: blur(4px);
            transition: opacity 0.3s ease;
        }

        .modal-content {
            background: linear-gradient(145deg, #ffffff 0%, #f8f9fa 100%);
            margin: 5% auto;
            padding: 30px;
            border-radius: 16px;
            width: 90%;
            max-width: 600px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
            position: relative;
            animation: slideIn 0.4s ease-out;
        }

        @keyframes slideIn {
            from {
                transform: translateY(-50px);
                opacity: 0;
            }
            to {
                transform: translateY(0);
                opacity: 1;
            }
        }

        .close {
            color: #999;
            position: absolute;
            right: 20px;
            top: 15px;
            font-size: 28px;
            font-weight: bold;
            transition: all 0.3s ease;
        }

        .close:hover,
        .close:focus {
            color: #FF4D4F;
            transform: rotate(180deg);
        }

        h2 {
            text-align: center;
            color: #165DFF;
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 2px solid #E8F3FF;
            font-size: 24px;
        }

        form {
            max-width: 500px;
            margin: 0 auto;
        }

        .form-group {
            margin-bottom: 25px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #555;
            font-size: 15px;
        }

        input[type="text"], textarea, select {
            width: 100%;
            padding: 14px 18px;
            border: 1px solid #ddd;
            border-radius: 10px;
            font-size: 16px;
            background-color: #fff;
            transition: all 0.3s ease;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        }

        input[type="text"]:focus, textarea:focus, select:focus {
            border-color: #165DFF;
            outline: none;
            box-shadow: 0 0 0 4px rgba(22, 93, 255, 0.15);
        }

        textarea {
            min-height: 120px;
            resize: vertical;
        }

        .file-upload {
            position: relative;
            overflow: hidden;
            border-radius: 10px;
        }

        input[type="file"] {
            position: absolute;
            top: 0;
            right: 0;
            min-width: 100%;
            min-height: 100%;
            font-size: 100px;
            opacity: 0;
            cursor: pointer;
        }

        .file-upload-btn {
            display: block;
            width: 100%;
            padding: 14px;
            background: linear-gradient(135deg, #E8F3FF 0%, #D6E8FF 100%);
            color: #165DFF;
            border: 1px solid #C5D9FF;
            border-radius: 10px;
            text-align: center;
            font-weight: 500;
            transition: all 0.3s ease;
            box-shadow: 0 2px 5px rgba(22, 93, 255, 0.1);
        }

        .file-upload-btn:hover {
            background: linear-gradient(135deg, #D6E8FF 0%, #C5D9FF 100%);
            transform: translateY(-2px);
        }

        .btn {
            width: 100%;
            padding: 15px;
            border: none;
            border-radius: 10px;
            font-size: 17px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .btn-primary {
            background: linear-gradient(135deg, #165DFF 0%, #0047CC 100%);
            color: white;
        }

        .btn-primary:hover {
            background: linear-gradient(135deg, #0047CC 0%, #003AB3 100%);
            transform: translateY(-3px);
            box-shadow: 0 6px 15px rgba(22, 93, 255, 0.3);
        }

        .btn-secondary {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4ecf5 100%);
            color: #555;
            margin-bottom: 15px;
            border: 1px solid #ddd;
        }

        .btn-secondary:hover {
            background: linear-gradient(135deg, #e4ecf5 0%, #d5e0eb 100%);
            transform: translateY(-2px);
        }

        .error {
            color: #FF4D4F;
            text-align: center;
            margin-bottom: 20px;
            padding: 12px;
            background: rgba(255, 77, 79, 0.05);
            border-radius: 8px;
            border-left: 4px solid #FF4D4F;
            font-weight: 500;
        }

        .back-link {
            display: inline-block;
            margin-top: 25px;
            color: #165DFF;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.3s ease;
            font-size: 16px;
        }

        .back-link:hover {
            color: #0047CC;
            text-decoration: underline;
            transform: translateY(-1px);
        }

        .location-btn {
            margin-bottom: 25px;
        }

        .upload-info {
            font-size: 14px;
            color: #777;
            margin-top: 8px;
            font-style: italic;
        }

        .form-icon {
            margin-right: 8px;
        }

        @media (max-width: 768px) {
            .modal-content {
                margin: 10% auto;
                padding: 25px;
                width: 95%;
            }

            body {
                padding: 15px;
            }

            .page-title {
                font-size: 26px;
                margin-bottom: 25px;
            }

            h2 {
                font-size: 22px;
            }

            input[type="text"], textarea, select, .btn, .file-upload-btn {
                font-size: 15px;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <h1 class="page-title">紧急事件位置上报系统</h1>

    <div id="myModal" class="modal">
        <div class="modal-content">
            <span class="close">&times;</span>
            <h2>事件信息上报</h2>

            <% if (request.getAttribute("error") != null) { %>
            <div class="error"><%= request.getAttribute("error") %></div>
            <% } %>

            <form action="ReportDisasterServlet" method="post" enctype="multipart/form-data">
                <div class="form-group">
                    <label for="eventType">事件类型</label>
                    <select id="eventType" name="eventType" required>
                        <option value="">请选择事件类型</option>
                        <option value="火灾">🔥 火灾</option>
                        <option value="地震">🌏 地震</option>
                        <option value="化学品泄漏">🧪 化学品泄漏</option>
                        <option value="交通事故">🚗 交通事故</option>
                        <option value="其他">❓ 其他</option>
                    </select>
                </div>

                <div class="form-group">
                    <label for="address">详细地址</label>
                    <input type="text" id="address" name="address" placeholder="请输入具体位置或点击获取定位" required />
                </div>

                <div class="form-group">
                    <label for="status">当前状态描述</label>
                    <textarea id="status" name="status" rows="4" placeholder="请描述事件当前情况、影响范围、人员伤亡等信息..." required></textarea>
                </div>

                <div class="form-group">
                    <label for="image">上传现场图片（可选）</label>
                    <div class="file-upload">
                        <span class="file-upload-btn">📷 点击选择图片</span>
                        <input type="file" id="image" name="image" accept="image/*" />
                    </div>
                    <p class="upload-info">支持JPG、PNG格式，建议图片大小不超过5MB</p>
                </div>

                <div class="form-group location-btn">
                    <button type="button" class="btn btn-secondary" onclick="getLocation()">
                        📍 获取当前位置
                    </button>
                </div>

                <!-- 用户ID隐藏字段 -->
                <input type="hidden" name="userId" value="<%= session.getAttribute("userId") %>">

                <button type="submit" class="btn btn-primary">
                    🚀 提交上报
                </button>
            </form>
        </div>
    </div>

    <div style="text-align: center;">
        <a href="clviLianPage.jsp" class="back-link">
            ← 返回首页
        </a>
    </div>
</div>

<script>
    var modal = document.getElementById("myModal");
    var span = document.getElementsByClassName("close")[0];

    // 显示模态框
    modal.style.display = "block";

    // 关闭按钮事件
    span.onclick = function() {
        modal.style.display = "none";
    }

    // 点击模态框外部关闭
    window.onclick = function(event) {
        if (event.target == modal) {
            modal.style.display = "none";
        }
    }

    // 获取地理位置
    function getLocation() {
        if (navigator.geolocation) {
            // 显示加载状态
            const addressInput = document.getElementById("address");
            const originalValue = addressInput.value;
            addressInput.value = "正在获取位置信息...";
            addressInput.disabled = true;

            // 添加加载动画
            addressInput.classList.add("loading");

            navigator.geolocation.getCurrentPosition(
                function(position) {
                    addressInput.value = `纬度: ${position.coords.latitude.toFixed(6)}, 经度: ${position.coords.longitude.toFixed(6)}`;
                    addressInput.disabled = false;
                    addressInput.classList.remove("loading");

                    // 添加成功反馈
                    addressInput.style.borderColor = "#4CAF50";
                    setTimeout(() => {
                        addressInput.style.borderColor = "";
                    }, 2000);
                },
                function(error) {
                    // 处理定位失败情况
                    let errorMsg = "定位失败: ";
                    switch(error.code) {
                        case error.PERMISSION_DENIED:
                            errorMsg += "请允许位置权限";
                            break;
                        case error.POSITION_UNAVAILABLE:
                            errorMsg += "位置信息不可用";
                            break;
                        case error.TIMEOUT:
                            errorMsg += "请求超时";
                            break;
                        default:
                            errorMsg += "未知错误";
                    }
                    addressInput.value = originalValue;
                    addressInput.disabled = false;
                    addressInput.classList.remove("loading");

                    // 添加错误反馈
                    addressInput.style.borderColor = "#FF4D4F";
                    setTimeout(() => {
                        addressInput.style.borderColor = "";
                    }, 2000);

                    alert(errorMsg);
                },
                { timeout: 10000 } // 10秒超时
            );
        } else {
            alert("您的浏览器不支持地理位置功能");
        }
    }
</script>
</body>
</html>